package algotrader.fakeserver;

import java.io.FileInputStream;

import quickfix.Acceptor;
import quickfix.DefaultMessageFactory;
import quickfix.FileStoreFactory;
import quickfix.MessageFactory;
import quickfix.MessageStoreFactory;
import quickfix.ScreenLogFactory;
import quickfix.SessionSettings;
import quickfix.SocketAcceptor;

public class FakeFixServer {
	private Acceptor acceptor;
	private FakeAcceptorFixApplication fixApp;
	public FakeFixServer() {
		try {
			setAcceptor();
			acceptor.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void setAcceptor() {
		try {
			String initiatorFileName = "mdsAcceptorTest.cfg";
			SessionSettings initiatorSettings = new SessionSettings(
					new FileInputStream(initiatorFileName));
			MessageStoreFactory initiatorStoreFactory = new FileStoreFactory(
					initiatorSettings);

			MessageFactory messageFactory = new DefaultMessageFactory();
			ScreenLogFactory screenLog = new ScreenLogFactory(true, true, true);

			fixApp = new FakeAcceptorFixApplication();
			acceptor = new SocketAcceptor(fixApp, initiatorStoreFactory,
					initiatorSettings, screenLog, messageFactory);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public FakeAcceptorFixApplication getFixApp() {
		return fixApp;
	}
	public void stop() {
		acceptor.stop();
	}
	
}
